package com.system.user.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.system.common.bean.Address;
import com.system.common.service.IAddressService;
import com.system.common.util.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/address")
public class AddressController {

    @DubboReference
    private IAddressService addressService;

    @PostMapping("/add")
    public Result add(@RequestBody Address address){
        addressService.addAddress(address);
        return Result.ok("添加地址成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        addressService.deleteAddress(id);
        return Result.ok("删除地址成功");
    }

    @PutMapping("/update")
    public Result update(@RequestBody Address address){
        addressService.updateAddress(address);
        return Result.ok("修改地址成功");
    }

    @GetMapping("/list")
    public Result list(){
        return Result.ok("获取地址列表成功",addressService.getAddressList());
    }

    @GetMapping("/page")
    public Result page(Address address, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        return Result.ok("获取地址列表成功",addressService.getPage(address, new Page<>(pageNum, pageSize)));
    }

    @GetMapping("/getAddressById/{id}")
    public Result getAddressById(@PathVariable Integer id){
        return Result.ok("获取地址成功",addressService.getAddressById(id));
    }

    @GetMapping("/getAddressByUserId/{userid}")
    public Result getAddressByUserId(@PathVariable Integer userid){
        return Result.ok("获取地址成功",addressService.getAddressByUserId(userid));
    }
}
